package com.ruoyi.web.controller.shopping;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.shopping.domain.BbsComments;
import com.ruoyi.shopping.service.IBbsCommentsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 论坛评论Controller
 *
 * @author ruoyi
 * @date 2022-06-20
 */
@RestController
@RequestMapping("/bbsComments/bbsComments")
public class BbsCommentsController extends BaseController
{
    @Autowired
    private IBbsCommentsService bbsCommentsService;

    /**
     * 查询论坛评论列表
     */
    @PreAuthorize("@ss.hasPermi('bbsComments:bbsComments:list')")
    @GetMapping("/list")
    public TableDataInfo list(BbsComments bbsComments)
    {
        startPage();
        List<BbsComments> list = bbsCommentsService.selectBbsCommentsList(bbsComments);
        return getDataTable(list);
    }

    /**
     * 导出论坛评论列表
     */
    @PreAuthorize("@ss.hasPermi('bbsComments:bbsComments:export')")
    @Log(title = "论坛评论", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BbsComments bbsComments)
    {
        List<BbsComments> list = bbsCommentsService.selectBbsCommentsList(bbsComments);
        ExcelUtil<BbsComments> util = new ExcelUtil<BbsComments>(BbsComments.class);
        return util.exportExcel(list, "论坛评论数据");
    }

    /**
     * 获取论坛评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('bbsComments:bbsComments:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bbsCommentsService.selectBbsCommentsById(id));
    }

    /**
     * 新增论坛评论
     */
    @PreAuthorize("@ss.hasPermi('bbsComments:bbsComments:add')")
    @Log(title = "论坛评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BbsComments bbsComments)
    {
        return toAjax(bbsCommentsService.insertBbsComments(bbsComments));
    }

    /**
     * 修改论坛评论
     */
    @PreAuthorize("@ss.hasPermi('bbsComments:bbsComments:edit')")
    @Log(title = "论坛评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BbsComments bbsComments)
    {
        bbsComments.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(bbsCommentsService.updateBbsComments(bbsComments));
    }

    /**
     * 删除论坛评论
     */
    @PreAuthorize("@ss.hasPermi('bbsComments:bbsComments:remove')")
    @Log(title = "论坛评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bbsCommentsService.logicDeleteBbsComments(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
